package com.zx.stock.controllers;

import com.zx.stock.common.Const;
import com.zx.stock.common.Result;
import com.zx.stock.common.ResultEnum;
import com.zx.stock.entity.StockAgency;
import com.zx.stock.mapper.StockAgencyMapper;
import com.zx.stock.utils.JSONUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/agency")
public class AgentController {

    @Resource
    private StockAgencyMapper stockAgencyMapper;

    //列表
    @ResponseBody
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public Result list(){

        Map<String,Object> params = new HashMap<>();
        params.put("status", Const.N);
        List<StockAgency> list = stockAgencyMapper.list(params);
        return new Result(list);
    }

    //列表
    @ResponseBody
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    public Result update(@RequestBody Map<String,Object> params){
        if (params==null)return new Result(ResultEnum.FAILED);

        StockAgency agent = JSONUtil.mapToObject(params,StockAgency.class);
        if (agent!=null){
            agent.setStatus(Const.Y);
            agent.setMtime(new Date());
            stockAgencyMapper.update(agent);
        }


        return new Result();
    }

}
